<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改药品信息')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-info-edit" th:object="${tDrugInfo}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">药品名称：</label>
                <div class="col-sm-8">
                    <input name="drugName" th:field="*{drugName}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">药品别名：</label>
                <div class="col-sm-8">
                    <input name="drugAlias" th:field="*{drugAlias}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">药品分类：</label>
                <div class="col-sm-8">
                    <select name="drugType" id="drugType" class="form-control" th:with="type=${@dict.getType('sys_drug_type')}" onchange="change()">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{drugType}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">药品类别：</label>
                <div class="col-sm-8">
                    <select name="drugCategory" id = "drugCategory" class="form-control">
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">药品规格：</label>
                <div class="col-sm-8">
                    <input name="drugSpecs" th:field="*{drugSpecs}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">单价：</label>
                <div class="col-sm-8">
                    <input name="unitPrice" th:field="*{unitPrice}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">零售价：</label>
                <div class="col-sm-8">
                    <input name="retailPrice" th:field="*{retailPrice}" class="form-control" type="text" required>
                </div>
            </div>
<!--            <div class="form-group">    -->
<!--                <label class="col-sm-3 control-label">库存：</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <input name="stock" th:field="*{stock}" class="form-control" type="text">-->
<!--                </div>-->
<!--            </div>-->
            <div class="form-group">    
                <label class="col-sm-3 control-label">药品单位：</label>
                <div class="col-sm-8">
                    <input name="drugCompany" th:field="*{drugCompany}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">厂家：</label>
                <div class="col-sm-8">
                    <input name="manufactor" th:field="*{manufactor}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">排序：</label>
                <div class="col-sm-8">
                    <input name="sort" th:field="*{sort}" class="form-control" type="text" required>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "business/drugInfo";
        var business_zsl = [[${@dict.getType('business_zsl')}]];
        var business_fzsl = [[${@dict.getType('business_fzsl')}]];
        var business_qt = [[${@dict.getType('business_qt')}]];
        $("#form-info-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-info-edit').serialize());
            }
        }

        function change(){
            var drugTypes = $("#drugType").find("option:selected").val();
            var drugCategory = $("#drugCategory");
            drugCategory[0].length = 0;
            var arr = [];
            if("business_zsl" == drugTypes){
                arr = business_zsl;
            }else if("business_fzsl" == drugTypes){
                arr = business_fzsl;
            }else{
                arr = business_qt;
            }
            var drugCategoryValue = [[${tDrugInfo.drugCategory}]]
            $.each(arr, function (i, val) {
                if(val.dictValue == drugCategoryValue){
                    drugCategory.append('<option value="' + val.dictValue + '" selected="selected">' + val.dictLabel + '</option>');
                }else {
                    drugCategory.append('<option value="' + val.dictValue + '">' + val.dictLabel + '</option>');
                }
            });
        }

        $(function(){
            change();
        })
    </script>
</body>
</html>